package com.controller;

import com.entity.Report;
import com.service.impl.BlogServiceImpl;
import com.service.impl.ReportServiceImpl;
import com.service.intf.BlogService;
import com.service.intf.ReportService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class ReportServlet extends BaseServlet {
    private ReportService reportService = new ReportServiceImpl();
    BlogService blogService = new BlogServiceImpl();

    protected void addReport(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userName = req.getParameter("userName");
        String reportContent = req.getParameter("reportContent");
        Integer userId = blogService.queryUserIdByUserName(userName);
        reportService.addReport(userId, reportContent);
        resp.sendRedirect(req.getContextPath() + "/blogServlet?action=page&username=" + userName);


    }


    protected void queryReport(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        List<Report> reports = reportService.queryReport();


        req.getSession().setAttribute("reports",reports);


        req.getRequestDispatcher("/pages/report/report_list.jsp").forward(req, resp);
    }
}